package com.crimerank;

import com.crimerank.data.StopCrime;

import android.os.Bundle;
import android.view.View;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

public class StationCrime extends BaseActivity {
    
	StopCrime obj = null;
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.stationcrime);
             
        obj = (StopCrime)getIntent().getSerializableExtra("StopCrimeObj");
        TextView stopName = (TextView) findViewById(R.id.stationCrimeName);
		stopName.setText(obj.getName());
		TextView stationRank = (TextView) findViewById(R.id.stationCrimeRank);
		stationRank.setText("Rank: " + obj.getRank());
        
		if(!obj.getCrimeAggregate().equals("null")){
			TableLayout tl = (TableLayout) findViewById(R.id.crimeTable);
			addRows(tl, obj.getCrimeAggregate());
		}
    }
	
	private void addRows(TableLayout tl, String aggregate){
		
		String [] result = aggregate.split(",");
		
		for(int i = result.length - 1; i >= 0; i--){
			String str = result[i];
			str = str.replaceAll("[\\{\\}\\\"]", "");
			
			String [] tmp = str.split(" : ");
			
			TableRow tr = new TableRow(this);
	
			TextView text = new TextView(this);
			text.setText(Integer.toString(result.length - i));
			text.setSingleLine(true);
			tr.addView(text);
	
			text = new TextView(this);
			text.setText(tmp[1]);
			text.setSingleLine(true);
			tr.addView(text);
	
			text = new TextView(this);
			text.setText(tmp[0]);
			text.setSingleLine(true);
			tr.addView(text);
	
			tl.addView(tr);
		}
	}
	
	public void onClick(View v) {
		SafetyDialog myDialog = null;
		switch (v.getId()) {
		case (R.id.preventtheft):
			myDialog = new SafetyDialog(this,android.R.style.Theme);
			myDialog.setTitle("Help prevent theft and fraud");
			myDialog.setContentView(R.layout.preventtheft);
	        myDialog.show();
	        break;
		case (R.id.preventautotheft):
			myDialog = new SafetyDialog(this,android.R.style.Theme);
			myDialog.setTitle("Help prevent auto theft");
			myDialog.setContentView(R.layout.preventautotheft);
	        myDialog.show();
	        break;
		}
	}
}
